#include "gwapplication.h"

using namespace gwBedrockApp;

gwApplication* gwApplication::g_pApplication = gwNULL;

/***************************************************************************************************************************/
gwApplication::gwApplication():
m_strCompanyName("GW System"),
m_strAppName("GW Engine Demo"),
m_strAppVersion("1.00"),
m_bIsOpen(false),
m_bRunning(false),
m_lReturnCode(0)
{

}

/***************************************************************************************************************************/
gwApplication::~gwApplication()
{

}

/***************************************************************************************************************************/
bool
gwApplication::Open()
{
        gwAssert(!this->m_bIsOpen);
        m_bIsOpen = true;
        m_bRunning = true;
        return m_bIsOpen;
}

/***************************************************************************************************************************/
void
gwApplication::Close()
{
        gwAssert(this->m_bIsOpen);
        m_bIsOpen = false;
}

/***************************************************************************************************************************/
void
gwApplication::Run()
{
        //do nothing, override this function as you wish
}

/***************************************************************************************************************************/
int
gwApplication::Main(int argc, char** argv)
{
        SetCommandLineArgs(gwCommandLine::ConvertCmdArgToString(argc,argv));
        if(gwBedrockApp::gwApplication::g_pApplication->Open())
        {
                while(m_bRunning)
                {
                        gwBedrockApp::gwApplication::g_pApplication->Run();
                }
                gwBedrockApp::gwApplication::g_pApplication->Close();
        }

        return gwBedrockApp::gwApplication::g_pApplication->GetReturnCode();
}

///@brief  hide standard entry here
/***************************************************************************************************************************/
int main(int argc, char** argv)
{
        long returnCode = 0;
        if(gwBedrockApp::gwApplication::g_pApplication)
        {
                returnCode = gwBedrockApp::gwApplication::g_pApplication->Main(argc,argv);

                gw_delete(gwBedrockApp::gwApplication::g_pApplication);
                gwBedrockApp::gwApplication::g_pApplication = 0;
        }

        return returnCode;
}
